package mqq.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Class for a line in an Decision Lines Event
 * Used to keep track of the edges
 * @author mqq
 */
public class Line {
	/** The choice above this line */
	String choice = "";
	
	/** The position of this line (start at 0) */
	int position;
	
	/** The edges attached to this line in an ordered list*/
	public List<Edge> edges = new ArrayList<Edge>();
	
	public Line(int n) {
		this.position = n;
	}
	
	/**
	 * Find the next edge in the ordered list below a certain height
	 * @param height  The height of the current edge
	 * @return  The next edge; null if run out of edge
	 */
	public Edge nextEdge(int height) {
		int min = Integer.MAX_VALUE;
		int numEdges = this.edges.size();
		int nextEdge = -1;
		for (int i = 0; i < numEdges; i++) {
			int diff = this.edges.get(i).height - height;
			if (diff > 0 && diff < min) {
				min = diff;
				nextEdge = i;
			}
		}
		if (nextEdge >= 0) {
			return this.edges.get(nextEdge);
		} else {
			return null;
		}
	}
	
	/**
	 * Set the choice of this line
	 * @param choice  The new choice
	 */
	public void setChoice(String choice) {
		this.choice = choice;
	}
	
	/**
	 * Get the choice of this line
	 * @return  The choice of this line
	 */
	public String getChoice() {
		return this.choice;
	}
}
